package com.huike.business.service.impl;


import com.huike.business.domain.TbBusiness;
import com.huike.business.domain.TbBusinessTrackRecord;
import com.huike.business.domain.vo.BusinessTrackVo;
import com.huike.business.mapper.TbBusinessMapper;
import com.huike.business.mapper.TbBusinessTrackRecordMapper;
import com.huike.business.domain.TbBusinessTrackRecord;
import com.huike.business.mapper.TbBusinessTrackRecordMapper;
import com.huike.business.service.ITbBusinessTrackRecordService;
import com.huike.clues.domain.TbClue;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.utils.DateUtils;
import com.huike.common.utils.SecurityUtils;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 商机跟进记录Service业务层处理
 * 
 * @author wgl
 * @date 2021-04-28
 */
@Transactional
@Service
public class TbBusinessTrackRecordServiceImpl implements ITbBusinessTrackRecordService {
    @Autowired
    private TbBusinessTrackRecordMapper tbBusinessTrackRecordMapper;
    
    @Autowired
    private TbBusinessTrackRecordMapper tbBusinessTrackRecordMapper;
    @Autowired
    private TbBusinessMapper tbBusinessMapper;
    
    /**
     * 新增商机跟进记录
     *
     * @param businessTrackVo
     */
    @Override
    public int add(BusinessTrackVo businessTrackVo) {
        //第一步就是更新线索
        
        TbBusiness tbBusiness = new TbBusiness();
        BeanUtils.copyProperties(businessTrackVo, tbBusiness);
        tbBusiness.setStatus(TbClue.StatusType.FOLLOWING.getValue());
        tbBusiness.setId(businessTrackVo.getBusinessId());
        tbBusinessMapper.update(tbBusiness);
        //第二步新增跟进记录
    
        TbBusinessTrackRecord tbBusinessTrackRecord = new TbBusinessTrackRecord();
        BeanUtils.copyProperties(businessTrackVo,tbBusinessTrackRecord);
        tbBusinessTrackRecord.setCreateTime(DateUtils.getNowDate());
        tbBusinessTrackRecord.setCreateBy(SecurityUtils.getUsername());
        int row = tbBusinessTrackRecordMapper.add(tbBusinessTrackRecord);
        
            return row;
        }
    
    /**
     * 商家跟进记录列表
     * @param id
     * @return
     */
    public List<TbBusinessTrackRecord> list(Long id){
        // 1.调用mapper查询id
        List<TbBusinessTrackRecord> trackRecordList = tbBusinessTrackRecordMapper.list(id);
        
    
        // 2.返回结果
        return trackRecordList;

    /**
     * 查询所有跟进记录
     *
     * @param id
     * @return
     */
    @Override
    public List<TbBusinessTrackRecord> findAllRecord(Long id) {
        List<TbBusinessTrackRecord> allRecord = tbBusinessTrackRecordMapper.findAllRecord(id);
        return allRecord;
    }
     }
}
